//
// Created by hjie on 23-6-23.
//

#include "base_logic_module.h"
#include "user_inout_module.h"
#include "publish_subscribe_module.h"
#include "heart_beat_module.h"
#include "message_router.h"
#include "./../protocol/msg_key.h"

void BaseLogicModule::RegisterLogicModule()
{
    auto inout = new UserInOutModule("in_out");
    auto pubsub = new PublishSubscribeModule("pub_sub");
    auto heart_beat = new HeartBeatModule("heart_beat");

    MessageRouter::Instance()->AddLogicModule(inout);
    MessageRouter::Instance()->AddLogicModule(pubsub);
    MessageRouter::Instance()->AddLogicModule(heart_beat);
}

BaseLogicModule::BaseLogicModule()
{

}

BaseLogicModule::~BaseLogicModule()
{

}

void BaseLogicModule::InitResponseHeader(rapidjson::Document &input, rapidjson::Document &output)
{
    output.SetObject();
    output.AddMember(header_k, rapidjson::Value(rapidjson::kObjectType), output.GetAllocator());
    output.AddMember(content_k, rapidjson::Value(rapidjson::kObjectType), output.GetAllocator());

    output[header_k].CopyFrom(input[header_k], output.GetAllocator());
    output[content_k].CopyFrom(input[content_k], output.GetAllocator());
}